#!/usr/local/bin/rc

leak=0
recurse=0

while (! ~ $#* 0 && ~ $1 -*) {
	switch ($1) {
		case -c; shift; leak=1
		case -r; shift; recurse=1
		case -*; echo 'usage:' `{basename $0} '[-r] [-c] files' >[1=2]
			exit 1
	}
}

fn check {
	if (~ $leak 1)
		valgrind -q ./$1
	if not
		./$1
}

fn tst {
	if (check $1)
		echo 'pass	' $1
	if not
		echo 'FAIL	' $1
}

fn proc {
	for (x in $*) {
		if (test -d $x) {
			if (~ $recurse 1) {
				cd $x
				echo `{pwd}
				proc `{ls -dF * | sed -n 's/\*$//p' >[2] /dev/null}
				proc `{ls -1d */ >[2] /dev/null}
				cd ..
			}
		}
		if not
   			if (test -x $x) tst $x
	}
}

proc $*
